//
//  MapViewController.m
//  CarHome
//
//  Created by 王建男 on 14-9-23.
//  Copyright (c) 2014年 WJN_work@163.com. All rights reserved.
//

#import "MapViewController.h"

@interface MapViewController ()

@end

@implementation MapViewController

- (void)dealloc
{
    [_web release];
    _web = nil;
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
}

//创建webview ， 添加返回button

- (void)creatMapView:(NSString *)string
{
    
    self.view.backgroundColor = myColor_dark;
    
    _web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height - 20)];
    _web.delegate = self;
     [_web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:string]]];
    [_web setBackgroundColor:[UIColor blackColor]];
    [self.view addSubview:_web];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:CGRectMake(0, 20, 40, 20)];
    [button setTitleEdgeInsets:UIEdgeInsetsMake(- 5, 5, 5, - 5)];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithRed:60 / 256.0 green:60 / 256.0 blue:60 / 256.0 alpha:1.0] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_web addSubview:button];
}

- (void)buttonAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark -
#pragma mark 设置网址，添加坐标

- (void)setWebUrl:(NSString *)ion Andlat:(NSString *)lat Andname:(NSString *)name
{
    NSMutableString *string = [NSMutableString stringWithFormat:@"%@",MapUrl];
    
    NSString *load = [NSString stringWithFormat:@"%@,%@",ion, lat];
    
    NSRange subStr = [string rangeOfString:@"parameter1"];
    
    if (subStr.location != NSNotFound) {
        [string replaceCharactersInRange:subStr withString:load];
    }
    
    NSRange subStrs = [string rangeOfString:@"parameter2"];
    if (subStrs.location != NSNotFound) {
        [string replaceCharactersInRange:subStrs withString:name];
    }
    
    
    NSString *strings = [string stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    
   
    [self creatMapView:strings];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
